

cc.Class({
    extends: cc.Component,

    properties: {
        headSprite:cc.Node,
        leaveSprite:cc.Node,
        nameLabel:cc.Label,
        scoreLabel:cc.Label,
        userInfo:null,
        rankLabel:cc.Label
      
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        
  
    },

    start () {

     
    },

     init(userDic){
        console.log('信息',userDic)
        this.userInfo=userDic
        this.scoreLabel.getComponent(cc.Label).string=this.userInfo["score"]
        this.nameLabel.getComponent(cc.Label).string=this.userInfo["name"]

        
         if(userDic["avatar"]){
            var that =this
            cc.loader.load({url: userDic["avatar"], type: 'png'}, function(err,img){

                var mylogo  = new cc.SpriteFrame(img); 
    
                that.headSprite.getComponent(cc.Sprite).spriteFrame = mylogo;
    
                that.headSprite.width=82
    
                that.headSprite.height=82
                
            });
         }
        

        var that = this

        if(userDic["user_rank"]==1){
            console.log("第一名")
            let _this = that
            cc.loader.loadRes("leave_1", cc.SpriteFrame, function (err, spriteFrame) {
         
              _this.leaveSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
 
            });

        }else if(userDic["user_rank"]==2){
            console.log("第2名")
            let _this = that
            cc.loader.loadRes("leave_2", cc.SpriteFrame, function (err, spriteFrame) {
         
              _this.leaveSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
 
            });

        }else if(userDic["user_rank"]==3){
            console.log("第3名")
            let _this = that
            cc.loader.loadRes("leave_3", cc.SpriteFrame, function (err, spriteFrame) {
         
              _this.leaveSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
 
            });

        }
        else{
            console.log("除前三名")
              let _this = that
              that.rankLabel.node.active=true
                that.rankLabel.getComponent(cc.Label).string=userDic["user_rank"]
            cc.loader.loadRes("排名底框", cc.SpriteFrame, function (err, spriteFrame) {
         
              _this.leaveSprite.getComponent(cc.Sprite).spriteFrame = spriteFrame;
 
            });  
        
        }

       

     }
});
